package com.innovation.client;

import org.apache.log4j.Logger;

import com.innovation.message.ServerMessageProto.ServerMessage;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class TcpClientHandler extends SimpleChannelInboundHandler<ServerMessage> {
	private static Logger logger = Logger.getLogger(TcpClientHandler.class);
	@Override
	protected void channelRead0(ChannelHandlerContext ctx, ServerMessage msg) throws Exception {
		Channel channel = ctx.channel();
		synchronized (channel) {
			//设置服务器端返回的数据
			TcpClient.responseData.put(channel, msg);

			channel.notify();
			logger.info("notify:"+channel+" hash="+channel.hashCode());
		}		
	}
	
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }
}
